'''
version python 3
数据结构-图
基于广度优先算法实现
'''

from collections import deque


def persion_is_xs(name):
    return name[-1] == "m"


def search(name):   
    search_queue = deque()
    search_queue += graph[name]
    searched = []
    while search_queue:
        person_name = search_queue.popleft()
        if person_name not in searched:
            if persion_is_xs(person_name):
                print(person_name + "是芒果商人")
                return True
            else:
                search_queue += graph[person_name]
                searched.append(person_name)
    return False


if __name__ == "__main__":
    graph = {'you': ["aliace", "bob", "claire"],
             'bob': ["anuj", "peggy"],
             'aliace':["peggy"],
             'claire': ["thom", "jonny"],
             'anuj': [],
             'peggy': [],
             'thom': [],
             'jonny': [],
             }
    search('you')